import {request} from "@/utils/request";
import type {PageResult} from "@/types/PageResult";
import type {AnimalSearchResult, AnimalsListItem, PicDetailItem} from "@/types/animals";


/**
 * 根据搜索关键词和类型返回对应数据
 * @param keyword 关键词
 * @param data  分类
 * @param data.type 过滤条件默认0—全部，1—热度，2—评分
 */
export const getAnimalsListBySearchApi = (keyword: string, data: {
    page: number,
    pageSize: number,
    categoryId?: string,
    type: number
}) => {
    data.type=data.type-1 // 跟后端规则对齐
    return request<PageResult<AnimalSearchResult[]>>({
        method: "GET",
        url: `/AW/user/search`,
        data: {
            ...data,
            keyword
        }
    })
}

/**
 * 根据传入id的数组去重新动物预览信息
 * @param ids 动物id
 */
export const getAnimalsListApi = (ids: string[]) => {
    return request<AnimalsListItem[]>({
        method: "GET",
        url: '/AW/list',
        data: {
            ids
        }
    })
}

/**
 * 获取动物图集详细信息
 * @param id
 */
export const getPicDetailApi = (id: number) => {
    return request<PicDetailItem>({
        method: 'GET',
        url: `/AW/detail/pic/${id}`,
    })
}